#include "Blocks/ChestBlock.h"
#include "Components/ComponentMiner.h"
#include "Components/ComponentCreature.h"
#include "Components/ComponentCreatureModel.h"

namespace PocketSurvival
{
    BlockPlacementData ChestBlock::getPlacementValue(ComponentMiner *componentMiner, int32_t value, const TerrainRaycastResult &raycastResult)
    {
        Vector3 forward = componentMiner->componentCreature->componentCreatureModel->getEyeRotation().toMatrix().getForward();
        float numBuff[4] = {
            Vector3::Dot(forward, FastVector3::UnitZ),
            Vector3::Dot(forward, FastVector3::UnitX),
            Vector3::Dot(forward, FastVector3::DecUnitZ),
            Vector3::Dot(forward, FastVector3::DecUnitX)};
        uint32_t targetIndex = MathUtils::MaxIndex<float>(numBuff, 4);
        int32_t data = 0;
        switch (targetIndex)
        {
        case 0:
            data = 2;
            break;
        case 1:
            data = 3;
            break;
        case 2:
            data = 0;
            break;
        case 3:
            data = 1;
            break;
        }
        BlockPlacementData result;
        result.value = Terrain::MakeBlockValue(getIndex(), 0, data);
        result.cellFace = raycastResult.cellFace;
        return result;
    }

    int32_t ChestBlock::getIndex()
    {
        return Index();
    }
    const std::string &ChestBlock::getBlockName()
    {
        static std::string blockName = "ChestBlock";
        return blockName;
    }

} // namespace PocketSurvival
